/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
 *       Filename:  crc32.c
 *    Description:  Реализация вычисления CRC32
 *
 *        Version:  1.0
 *        Created:  11.02.2013 23:53:21
 *         Author:  Aleksey Golovchenko (lexgolovchenko@gmail.com)
 *   Organization:  St.Petersburg State Polytecnical Universisy
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include <stdint.h>
#include "../cpp_templates/table_gen.h"

static crc32table<0xEDB88320UL> crc32tbl;
 
unsigned long crc32(void *data, unsigned long size)
{
    unsigned char *buf = (unsigned char *)data;
    unsigned long crc = 0xFFFFFFFF;

    while (size--) {
        crc = (crc >> 8) ^ crc32tbl[(crc ^ *buf++) & 0xFF];
    }

    return crc ^ 0xFFFFFFFF;
}
